#include "../include/Heros.h"

Heros::Heros(const std::string &fname, sf::Color couleur, sf::Vector2f pos, int speed,Style style,Katana katana) :
Personnage(fname,couleur,pos,speed), m_Style(style), m_KatanaEquipe(katana)
{
    m_KatanaImg.LoadFromFile(fname);
    m_KatanaImg.CreateMaskFromColor(couleur);


    for (int i = 7; i<=10; i++)
    {
        m_Style1B.PushFrame(Frame(&m_KatanaImg, sf::Rect<int>(cote_Carre*i-cote_Carre, 0, cote_Carre*i, cote_Carre)));
        m_Style1G.PushFrame(Frame(&m_KatanaImg, sf::Rect<int>(cote_Carre*i-cote_Carre, 32, cote_Carre*i, cote_Carre*2)));
        m_Style1D.PushFrame(Frame(&m_KatanaImg, sf::Rect<int>(cote_Carre*i-cote_Carre, 64, cote_Carre*i, cote_Carre*3)));
        m_Style1H.PushFrame(Frame(&m_KatanaImg, sf::Rect<int>(cote_Carre*i-cote_Carre, 96, cote_Carre*i, cote_Carre*4)));
    }

    m_animKatana.SetAnim(&m_Style1D);
    m_animKatana.SetFrameTime(0.1f);
    m_animKatana.Pause();
    m_animKatana.SetLoop(true);
    m_animKatana.SetCenter(0, 0);
    Hitting = 0;
    m_AnimFinie = false;
}

Heros::~Heros()
{
    //dtor
}

void Heros::Attaquer()
{
    Hitting += 1;
    m_AnimFinie = false;
    m_animKatana.SetFrame(0);

}

void Heros::UpdateEpee(float ElapsedTime)
{
    if (!m_AnimFinie) // Si l'anim en cours n'est pas finie
    {
        switch (m_direction) //On teste dans quelle direction le joueur tape
        {
            case GAUCHE :

            if (m_animKatana.GetAnim() != &m_Style1G ) // Si il n'était pas déjà vers la gauche
            m_animKatana.SetAnim(&m_Style1G);          // on met l'anim vers la gauche

            if ( m_animKatana.GetCurrentFrame() == 0 ) // Si on est à la frame 0 on le positionne selon  l'anim
            m_animKatana.SetPosition(m_animation.GetPosition().x,m_animation.GetPosition().y-32);

            if ( m_animKatana.GetCurrentFrame() == 1 )
            m_animKatana.SetPosition(m_animation.GetPosition().x-32 ,m_animation.GetPosition().y-32);

            if ( m_animKatana.GetCurrentFrame() == 2 )
            m_animKatana.SetPosition(m_animation.GetPosition().x-32 ,m_animation.GetPosition().y);

            if ( m_animKatana.GetCurrentFrame() == 3 ){
            m_animKatana.SetPosition(m_animation.GetPosition().x-32 ,m_animation.GetPosition().y);
            m_AnimFinie = true; //On est a la fin de l'anim (dernière frame)
            }
        break;

        case DROITE :


            if (m_animKatana.GetAnim() != &m_Style1D )
            m_animKatana.SetAnim(&m_Style1D);

            if ( m_animKatana.GetCurrentFrame() == 0 )
            m_animKatana.SetPosition(m_animation.GetPosition().x,m_animation.GetPosition().y-32);

            if ( m_animKatana.GetCurrentFrame() == 1 )
            m_animKatana.SetPosition(m_animation.GetPosition().x+32 ,m_animation.GetPosition().y-32);

            if ( m_animKatana.GetCurrentFrame() == 2 )
            m_animKatana.SetPosition(m_animation.GetPosition().x+32 ,m_animation.GetPosition().y);

            if ( m_animKatana.GetCurrentFrame() == 3 ){
            m_animKatana.SetPosition(m_animation.GetPosition().x+32 ,m_animation.GetPosition().y);
            m_AnimFinie = true;
            }
        break;

        case HAUT :


            if (m_animKatana.GetAnim() != &m_Style1H )
            m_animKatana.SetAnim(&m_Style1H);

            if ( m_animKatana.GetCurrentFrame() == 0 )
            m_animKatana.SetPosition(m_animation.GetPosition().x+32,m_animation.GetPosition().y);

            if ( m_animKatana.GetCurrentFrame() == 1 )
            m_animKatana.SetPosition(m_animation.GetPosition().x+32 ,m_animation.GetPosition().y-32);

            if ( m_animKatana.GetCurrentFrame() == 2 )
            m_animKatana.SetPosition(m_animation.GetPosition().x ,m_animation.GetPosition().y-32);

            if ( m_animKatana.GetCurrentFrame() == 3 ){
            m_animKatana.SetPosition(m_animation.GetPosition().x ,m_animation.GetPosition().y-32);
            m_AnimFinie = true;
            }
        break;

        case BAS :


            if (m_animKatana.GetAnim() != &m_Style1B )
            m_animKatana.SetAnim(&m_Style1B);

            if ( m_animKatana.GetCurrentFrame() == 0 )
            m_animKatana.SetPosition(m_animation.GetPosition().x-32,m_animation.GetPosition().y);

            if ( m_animKatana.GetCurrentFrame() == 1 )
            m_animKatana.SetPosition(m_animation.GetPosition().x-32 ,m_animation.GetPosition().y+32);

            if ( m_animKatana.GetCurrentFrame() == 2 )
            m_animKatana.SetPosition(m_animation.GetPosition().x ,m_animation.GetPosition().y+32);

            if ( m_animKatana.GetCurrentFrame() == 3 ){
            m_animKatana.SetPosition(m_animation.GetPosition().x ,m_animation.GetPosition().y+32);
            m_AnimFinie = true;
            }
        break;
        }


        if (m_animKatana.IsPaused() ) // Si l'épée est en pause on la play :p
        m_animKatana.Play();

        if (m_animation.IsPaused()) // Si le joueur est en pause on le play
        m_animation.Play();

        m_animation.anim(ElapsedTime);  //On anime le tout
        m_animKatana.anim(ElapsedTime);

    }




   /*/ if (Hitting==0)
    {
        switch (m_direction)
        {

        case GAUCHE :
        if (!m_animKatana.IsStoped())
        m_animKatana.Stop();

        if(m_animation.GetAnim() != &m_Gauche)
        m_animation.SetAnim(&m_Gauche);

        m_AnimFinie = false;
        break;

        case DROITE :
        if (!m_animKatana.IsStoped())
        m_animKatana.Stop();

        if(m_animation.GetAnim() != &m_Droite)
        m_animation.SetAnim(&m_Droite);

        m_AnimFinie = false;
        }



    }//*/


}
